/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.faces.proteu.beans.strvalidator;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.faces.application.FacesMessage;



/**
 *
 * @author eros
 */
public class NameValidator implements Validator{

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

        String name = (String) value;
        FacesMessage message;
        if(name.length()<3){
            message = new FacesMessage();
            message.setDetail("Nome inferior a 3 caracteres");
            message.setSummary("Nome muito curto");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(message);
        }else if(name instanceof String){
            message = new FacesMessage();
            message.setDetail("Somente caracteres neste campo");
            message.setSummary("Nao numericos");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);

        }else if(name == null){
            message = new FacesMessage();
            message.setDetail("Este campo nao pode ser null");
            message.setSummary("valor invalido");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);

        }



    }



}
